#region

using Microsoft.Extensions.Localization;

using Volo.Abp.Localization;

#endregion

namespace Leo.Core.Domain.Shared
{
    public static class LocalizableStringExtensions
    {
        public static string GetValue(this IStringLocalizerFactory stringLocalizerFactory, ILocalizableString item)
        {
            string? value;
            if (item is FixedLocalizableString)
            {
                value = (item as FixedLocalizableString).Value;
            }
            else
            {
                LocalizableString? localizedString = item as LocalizableString;
                IStringLocalizer l = stringLocalizerFactory.Create(localizedString.ResourceType);
                value = l[localizedString.Name];
            }

            return value;
        }

        public static string GetValue(this ILocalizableString item, IStringLocalizerFactory stringLocalizerFactory)
        {
            string? value;
            if (item is FixedLocalizableString)
            {
                value = (item as FixedLocalizableString).Value;
            }
            else
            {
                LocalizableString? localizedString = item as LocalizableString;
                IStringLocalizer l = stringLocalizerFactory.Create(localizedString.ResourceType);
                value = l[localizedString.Name];
            }

            return value;
        }
    }
}